window.layuiFunciton = {};
window.opneLayer = {};
var tableObj = {};
var table_options = {};
//replace(/[^0-9.]/g,&quot;&quot;)
$.extend(window.layuiFunciton, {

    /**
     * 使用 nginx 启动页面时，可不配置ip 和端口
     * 使用 tomcat 时 为后端服务ip和端口和前缀
     * 请求的ip和端口 后端访问前缀   例如  http://caiyuankeji.vicp.io:8080
     */
    URL: '/tu',      //

    /**
     * 是否访问后台
     */
    requestType: true,

    /**
     * 发送一个Ajax请求
     *
     * @param _options
     *  url               请求地址
     *  method            请求方法类型：POST，GET
     *  data              请求发送的数据
     * responseData     true  返回原始的结果集  false  返回结果集点data
     *  success      请求后台返回成功之后的回调函数
     *  error        请求后台返回失败之后的回调函数
     */
    ajaxRequest: function (_options) {
        layui.use(['layer', 'form'], function () {
            var layer = parent.layer === undefined ? layui.layer : parent.layer
                , form = layui.form;
            _options = $.extend({
                url: '',
                method: 'get',
                data: {},
                async: false,   //是否为异步请求
                title: '数据加载中，请稍候...',
                dataType: "json",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",//"application/json; charset=utf-8",
                traditional: false,
                maskState: true,         //是否开启遮罩
                responseData: false,   // true  返回原始的结果集  false  返回结果集点data
                success: function (data) {

                },
                error: function (error) {
                    layer.msg("未知问题，请联系管理员！", {icon: 2, time: 2000});
                }
            }, _options);
            var layerIndex;
            $.ajax({
                url: _options.url,
                type: _options.method,
                cache: false,
                contentType: _options.contentType,
                dataType: _options.dataType,
                async: _options.async,   //是否为异步请求
                data: _options.data,
                traditional: false,
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader('token', window.localStorage.token);
                    if (_options.maskState) {
                        layerIndex = layer.msg(_options.title, {icon: 16, shade: 0.1, time: false});
                    }
                },
                complete: function () {
                    if (_options.maskState) {
                        layer.close(layerIndex);
                    }
                }
                ,
                success: function (response) {
                    if (response.code == '5000') {
                        layer.msg(response.message, {icon: 2, time: 2000}, function () {
                            window.parent.parent.location.href = '/page/login/login.html'
                        });
                    } else {
                        if (response.code == '99999') {
                            layer.msg("操作失败！", {icon: 2, time: 2000});
                        }
                        if (_options.responseData) {
                            _options.success(response);
                        } else {
                            _options.success(response.data);
                        }
                        form.render();
                    }
                }
                ,
                error: function (errorResponse) {
                    layer.close(layerIndex);
                    layer.msg("未知问题，请联系管理员！", {icon: 2, time: 2000});
                }
            });
        });
    },
    /**
     * 获取当前选中的  iframe URL 参数
     */
    getURLParamMap: function () {
        var paramMap = {};//初始化结果集
        //当前菜单ID
        var currentMenuId = window.currentMenuId == undefined ? window.parent.currentMenuId : window.currentMenuId;
        //获取菜单
        var sysMenuList = window.sysMenu == undefined ? window.parent.sysMenu : window.sysMenu;
        //遍历按钮
        if (currentMenuId != undefined && sysMenuList[currentMenuId] != undefined) {
            var data = sysMenuList[currentMenuId];
            if (data) {
                var url = data.menuUrl;
                var strs;
                if (url.indexOf("?") != -1) {
                    var str = url.substr(url.indexOf("?") + 1);
                    strs = str.split("&");
                    for (var i = 0; i < strs.length; i++) {
                        paramMap[strs[i].split("=")[0].replace(/\s+/g, "")] = (strs[i].split("=")[1].replace(/\s+/g, ""));
                    }
                }
            }
        }
        return paramMap;
    },
    /**
     * 建立长连接
     * 监听token 实现唯一登录
     * @param token
     */
    webSocket: function (token) {
        var websocket = null;
        //判断当前浏览器是否支持WebSocket
        if ('WebSocket' in window) {
            websocket = new WebSocket("ws://localhost:8002/tu/webSocket/" + token);
        } else {
            console.log('当前浏览器 Not support websocket')
        }
        //连接发生错误的回调方法
        websocket.onerror = function () {
            console.log("WebSocket连接发生错误");
        };
        //连接成功建立的回调方法
        websocket.onopen = function () {
            console.log("WebSocket连接成功");
        };
        //接收到消息的回调方法
        websocket.onmessage = function (event) {
            if (event.data && event.data.indexOf('{') < 0) {
                console.log(event.data)
            } else {
                var message = $.parseJSON(event.data);
                if (message.code == "2000") {
                    layuiFunciton.warnAlert(message.msg, function () {
                        window.parent.parent.location.href = '/page/login/login.html';
                    });
                }
            }
        };
        //连接关闭的回调方法
        websocket.onclose = function () {
            console.log("WebSocket连接关闭");
        };
        //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
        window.onbeforeunload = function () {
            websocket.close();
        };
    },
    /**
     * 实例化表格
     * tableId: 'sysMenu',
     url:  layuiFunciton.URL + '/sysMenu/selectSysMenuPage',
     id: 'sysMenuTabelId',
     searchFromId:'searchFrom',
     tableFilter:'newsList',  //表格监听名称,
     * tools 数据结构    必须定义 tableFilter 表格监听事件  例如 ：  tableFilter:'newsList',  //表格监听标识
     * edit:{ returnData:function (rowData) {}}
     ,del:{ returnData:function (rowData) {}}
     *
     * @param _options
     */
    tableInit: function (_options) {
        //当前菜单ID
        var currentMenuId = window.currentMenuId == undefined ? window.parent.currentMenuId : window.currentMenuId;
        //获取菜单权限
        var metadataList = window.metadata == undefined ? window.parent.metadata : window.metadata;
        //遍历按钮
        if (currentMenuId != undefined && metadataList[currentMenuId] != undefined) {
            var list = metadataList[currentMenuId];
            var metadata = {};//行工具
            var metadataTop = {};//头工具
            $.each(eval(list), function (index, value, array) {
                if (value.metadataTypes == 1 && value.metadataIcon != undefined && value.metadataIcon != '' && value.metadataIcon != null) {
                    if (metadata[value.metadataPath] == undefined) {
                        if (value.metadataIcon.indexOf("iconfont") >= 0)
                            metadata[value.metadataPath] = '<a class="' + value.metadataIcon + '" title="' + value.metadataName + '" lay-event="' + value.metadataCode + '"></a>&nbsp;&nbsp;';
                        else
                            metadata[value.metadataPath] = '<a class="iconfont"  title="' + value.metadataName + '" lay-event="' + value.metadataCode + '"><i class="' + value.metadataIcon + '"></i></a>&nbsp;&nbsp;';
                    } else {
                        if (value.metadataIcon.indexOf("iconfont") >= 0)
                            metadata[value.metadataPath] += '<a class="' + value.metadataIcon + '" title="' + value.metadataName + '" lay-event="' + value.metadataCode + '"></a>&nbsp;&nbsp;';
                        else
                            metadata[value.metadataPath] = '<a class="iconfont" title="' + value.metadataName + '" lay-event="' + value.metadataCode + '"><i class="' + value.metadataIcon + '"></i></a>&nbsp;&nbsp;';
                    }
                } else if (value.metadataTypes == 2) {
                    if (metadataTop[value.metadataPath] == undefined) {
                        metadataTop[value.metadataPath] = '<a class="layui-btn layui-btn-sm addeg_btn" lay-event="' + value.metadataCode + '">' + value.metadataName + '</a>'
                    } else {
                        metadataTop[value.metadataPath] += '<a class="layui-btn layui-btn-sm addeg_btn" lay-event="' + value.metadataCode + '">' + value.metadataName + '</a>';
                    }
                    Object.keys(metadataTop).forEach(function (key) {
                        _options.toolbar = '<div class="layui-btn-container">' + metadataTop[key] + '</div>';
                    });
                }
            });
            //根据权限添加操作
            if (metadata[_options.id] != undefined && !_options.colsTf) {
                _options.cols[0][_options.cols[0].length] = {
                    title: '操作',
                    align: "center",
                    templet: function () {
                        return metadata[_options.id];
                    },
                    fixed: 'right'
                };
            }
        }
        table_options[_options.id] = _options;
        layui.use(['layer', 'table', 'form', 'jquery'], function () {
            table = layui.table;
            layer = parent.layer === undefined ? layui.layer : top.layer;
            form = layui.form;
            var layerIndex = layer.msg('数据加载中，请稍候...', {icon: 16, shade: 0.1, time: false});
            tableObj[_options.id] = {table: table, layer: layer, form: form, pageIndex: 1, page: _options.page};
            var list = $("#" + _options.searchFromId).serializeArray(); //自动将form表单封装成json
            var refreshData = {};
            for (var i = 0; i < list.length; i++) {
                refreshData[list[i].name] = list[i].value;
            }
            _options = $.extend({
                id: '',         //id
                tableId: '',     //表格id
                searchFromId: '',  //搜索提交表单
                url: '',        //表格请路劲
                height: 'full-160',  //高度
                cellMinWidth: 95,
                page: {layout: ['prev', 'page', 'next', 'count', 'limit']}, //开启分页
                sort: true,
                toolbar: 'default', //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                totalRow: false, //开启合计行  {fixed:"left", type: "checkbox", width:50, totalRowText: '合计'},
                rowClick: false,  //默认关闭行点击事件
                limit: 15,
                limits: [15, 30, 50, 100],
                cols: '',
                defaultToolbar: ['filter', 'print', 'exports'],
                returnData: function (data) {

                }
            }, _options);
            //方法级渲染
            table.render({
                elem: '#' + _options.tableId,
                url: _options.url,
                cellMinWidth: _options.cellMinWidth,
                id: _options.id,
                page: _options.page, //开启分页
                height: _options.height,
                sort: true,
                toolbar: _options.toolbar,
                defaultToolbar: _options.defaultToolbar,
                totalRow: _options.totalRow,
                limit: _options.limit,
                limits: _options.limits,
                cols: _options.cols,
                where: refreshData,
                done: function (res, curr, count) {
                    if (res.code == '5000') {
                        layer.msg(res.message, {icon: 2, time: 2000}, function () {
                            window.parent.parent.location.href = '/page/login/login.html'
                        });
                    } else {
                        layer.close(layerIndex);
                        if (res.pageIndex)
                            tableObj[_options.id].pageIndex = res.pageIndex;
                        _options.returnData(res.data);
                    }
                }
            });
            /**
             * ***** 监听工具 ****** 格式******
             *
             * tools:{
                       edit:function (rowData) {
                           layer.alert('编辑行：<br>'+ JSON.stringify(rowData));
                           console.log(rowData)
                       }
                       ,del:function (rowData) {
                          ayer.alert('删除：<br>'+ JSON.stringify(rowData));
                          console.log(rowData)
                      },
                 */
            if (_options.tools != undefined && _options.tools != "" && _options.tools != {}) {
                //监听行工具事件
                table.on('tool(' + _options.tableFilter + ')', function (obj) {
                    var data = obj.data;
                    _options.tools[obj.event](data, this);
                });
                //监听头工具栏事件
                table.on('toolbar(' + _options.tableFilter + ')', function (obj) {
                    var data = obj.data;
                    if (typeof(eval(_options.tools[obj.event])) == "function") {
                        _options.tools[obj.event](data, this);
                    }
                });
                if (!_options.rowClick) {
                    //监听行单击事件（单击事件为：rowDouble）
                    table.on('row(' + _options.tableFilter + ')', function (obj) {
                        var data = obj.data;
                        if (_options.tools[_options.tableFilter] != undefined) {
                            _options.tools[_options.tableFilter](data, obj, this);
                        }
                        //标注选中样式
                        obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                    });
                    //双击事件
                    table.on('rowDouble(' + _options.tableFilter + ')', function (obj) {
                        var data = obj.data;
                        if (_options.tools['rowDouble'] != undefined) {
                            _options.tools['rowDouble'](data, obj, this);
                        }
                        //标注选中样式
                        obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                    });
                }
            }


            /**
             * ***监听 from 、table 两种类型     必须填写 **** 格式******
             *
             *filter:[{
                            types:'form',   //   注：仅支持 from 、table 两种类型  监听 table的 tools 请使用 tools 属性
                            filterTypes: 'switch',   //
                            filterName: 'enabledDemo',
                            returnData : function (obj) {
                                layer.alert('编辑行：<br>'+ JSON.stringify(obj));
                            }
                        },{
                            types:'table',   //   注：仅支持 from 、table 两种类型  监听 table的 tools 请使用 tools 属性  table 不用填写 filterName属性  表格监听器名称
                            filterTypes: 'edit',  //       例如 ：  table.on('edit(test3)', function(obj){}   对应属性    types.on('filterTypes(enabledDemo)')
                            returnData : function (obj) {
                                layer.alert('阿斯顿发生大法师的发：<br>'+ JSON.stringify(obj));
                            }
                        }
             ],    //表单监听
             */
            if (_options.filter != undefined && _options.filter != null) {
                for (var i = 0; i < _options.filter.length; i++) {
                    if (_options.filter[i].types == 'form') {
                        form.on(_options.filter[i].filterTypes + '(' + _options.filter[i].filterName + ')', _options.filter[i].returnData);
                    } else {
                        table.on(_options.filter[i].filterTypes + '(' + _options.tableFilter + ')', _options.filter[i].returnData);
                    }
                }
            }
        });
    },
    /**
     * 金额验证
     * @param obj
     */
    moneyValidation: function (inputId) {
        $(inputId).on('input propertychange', function () {
            //如果输入非数字，则替换为''
            this.value = this.value.replace(/[^\d\.]/g, '');
            //必须保证第一个为数字而不是.
            this.value = this.value.replace(/^\./g, '');
            //保证只有出现一个.而没有多个.
            this.value = this.value.replace(/\.{2,}/g, '.');
            //保证.只出现一次，而不能出现两次以上
            this.value = this.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
            //只能输入两位小数
            this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
        });
        $(inputId).change(function () {
            var num = $(this).val();
            num = Number(num).toFixed(2);
            $(this).val(num);
        });
    }
    ,
    /**
     *  获取UUID
     * @param len   长度
     * @param radix  进制
     */
    getUUID: function (len, radix) {
        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
        var uuid = [], i;
        radix = radix || chars.length;
        if (len) {
            // Compact form
            for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
        } else {
            // rfc4122, version 4 form
            var r;

            // rfc4122 requires these characters
            uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
            uuid[14] = '4';

            // Fill in random data. At i==19 set the high bits of clock sequence as
            // per rfc4122, sec. 4.1.5
            for (i = 0; i < 36; i++) {
                if (!uuid[i]) {
                    r = 0 | Math.random() * 16;
                    uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                }
            }
        }
        return uuid.join('');
    }
    ,
    /**
     *  金额转换大写
     */
    digitUppercase: function (n) {
        var fraction = ['角', '分'];
        var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
        var unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']];
        var head = n < 0 ? '欠' : '';
        n = Math.abs(n);
        var s = '';
        for (var i = 0; i < fraction.length; i++) {
            s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
        }
        s = s || '整';
        n = Math.floor(n);
        for (var i = 0; i < unit[0].length && n > 0; i++) {
            var p = '';
            for (var j = 0; j < unit[1].length && n > 0; j++) {
                p = digit[n % 10] + unit[1][j] + p;
                n = Math.floor(n / 10);
            }
            s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
        }
        return head + s.replace(/(零.)*零元/, '元')
                .replace(/(零.)+/g, '零')
                .replace(/^整$/, '零元整');
    }
    ,
    /**
     *
     * @param selectId  下拉列表位置   select  ID
     * @param code  数据字典类别编号
     * @param defaultCode 默认选择编号
     * @param assignment  true  赋值给  ID  文本
     */
    selectDict: function (selectId, code, defaultCode, assignment) {
        layui.use(['layer', 'form'], function () {
            var form = layui.form;
            layuiFunciton.ajaxRequest({
                url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode',
                method: 'get',
                maskState: false,
                data: {
                    typeCode: code,
                    enabled: 1
                },
                success: function (data) {
                    if (assignment) {
                        data.forEach(function (obj, index) {
                            if (obj.valCode == defaultCode) {
                                $("#" + selectId).html(obj.valName);
                            }
                        });
                    } else {
                        var optionHtml = '<option value=""></option>';
                        data.forEach(function (obj, index) {
                            if (obj.valCode == defaultCode) {
                                optionHtml += '<option value="' + obj.valCode + '" selected>' + obj.valName + '</option>';
                            } else {
                                optionHtml += '<option value="' + obj.valCode + '">' + obj.valName + '</option>';
                            }
                        });
                        $("#" + selectId).html(optionHtml);
                        form.render();
                    }
                }
            })
        });
    },
    /**
     *  根据字典值编码查询名称
     * @param valCode  数据字典值编号
     */
    getValNameByValCode: function (valCode) {
        var valName;
        layuiFunciton.ajaxRequest({
            url: layuiFunciton.URL + '/sys/dictVal/getValNameByValCode',
            method: 'get',
            maskState: false,
            data: {
                valCode: valCode
            },
            success: function (data) {
                if (data) {
                    valName = data.valName;
                }
            }
        });
        return valName;
    },
    /**
     *  len-长度最大位
     */
    randomChar: function (len) {
        len = len || 32;
        var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz1234567890';
        /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
        var maxPos = $chars.length;
        var pwd = '';
        for (i = 0; i < len; i++) {
            pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
        }
        return pwd;
    },
    /**
     * js 时间戳转时间
     * @param inputTime
     * @returns {string}
     */
    formatDateTime: function (inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
    }
    /**
     * js sessionStorage  存值
     * @param key
     @param value
     */
    , sessionStorageSet: function (key, value) {
        sessionStorage.setItem(key, JSON.stringify(value));
    }
    /**
     * js sessionStorage  取值
     * @param key
     @param value
     */
    , sessionStorageGet: function (key) {
        return JSON.parse(sessionStorage.getItem(key));
    }
    ,
    /**
     * searchFromId 查询表单ID
     * id 非表格ID
     * page  第几页  默认缓存页数
     *
     * 表格数据刷新
     */
    refresh: function (searchFromId, id, page) {
        var list = $("#" + searchFromId).serializeArray(); //自动将form表单封装成json
        var refreshData = {};
        for (var i = 0; i < list.length; i++) {
            refreshData[list[i].name] = list[i].value;
        }
        if (!page) {
            page = tableObj[id].pageIndex;
        }
        if (tableObj[id].page == false) {
            tableObj[id].table.reload(id, {
                where: refreshData
            });
        } else {
            tableObj[id].table.reload(id, {
                page: {
                    curr: page //重新从第 1 页开始
                }
                , where: refreshData
            });
        }
    },
    /**
     * 获取选中数据
     * @param id
     */
    getCheckData: function (id) {
        var checkStatus = tableObj[id].table.checkStatus(id);
        return checkStatus.data;
    },
    /**
     *  ****打开一个窗口****
     *  finder: body 以下哪些需要使用模板  默认  body内 第一个div
     *  所有参数同layui.open方法参数相同
     *  如需要模板引擎文档 - layui.laytpl  传参 data
     *  语法结构参照 layui.laytpl    http://www.layui.com/doc/modules/laytpl.html#syntax    模板语法
     *  end :function(){
     *      页面关闭触发
     *  }
     *  pageReady 是否回调
     * @param _options
     */
    layerOpen: function (_options) {
        layui.use(['laytpl', 'table', 'form', 'jquery'], function () {
            var laytpl = layui.laytpl
                , layer = layui.layer
                , table = layui.table
                , form = layui.form;
            var $window;
            if (_options.parentOpen) {
                layer = parent.layer == undefined ? layer : parent.layer;
                $window = parent.window
            } else {
                $window = window;
            }
            _options = $.extend({
                title: "",
                type: 2,
                offset: 'auto', //水平居中，垂直100px  'auto'
                area: ['80%', '80%'], //自定义宽高
                areaType: false,           //是否自定义宽高  false 铺满  true 自定义
                parentOpen: false,          //从父页面打开  默认false
                content: "",
                success: function (layero, index) {
                    if (_options.data != {} && _options.data != undefined && _options.data != null && _options.data != '') {
                        var body = layer.getChildFrame('body', index);
                        if (_options.finder != undefined && _options.finder != undefined && _options.finder != '') {
                            var childHtml = $(body).find(_options.finder).html();
                            $(body).find(_options.finder).html(template(childHtml, _options.data));
                        } else {
                            var childHtml = $(body).find("div").html();
                            $(body).find("div").html(template(childHtml, _options.data));
                        }
                    }
                    var iframeWin;
                    if (_options.parentOpen) {
                        iframeWin = parent.window[layero.find('iframe')[0]['name']];
                        if (!iframeWin) {
                            iframeWin = parent.parent.window[layero.find('iframe')[0]['name']];
                        }
                    } else {
                        iframeWin = window[layero.find('iframe')[0]['name']];
                    }
                    //执行表达式后重新初始化子级页面
                    if (typeof(eval(iframeWin.pageReady)) == "function") {
                        if (_options.callback) {
                            iframeWin.pageReady(_options.callback);
                        } else {
                            iframeWin.pageReady();
                        }
                    }
                }
            }, _options);
            //点击编辑按钮
            var index = layer.open(_options);
            $window.opneLayer = {layerObj: layer, index: index};
            if (_options.callback) {
                _options.callback.opneLayer = {layerObj: layer, index: index};
            }
            $window[_options.content] = index;
            if (!_options.areaType) {
                layer.full($window[_options.content]);
                //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
                $(window).on("resize", function () {
                    layer.full($window[_options.content]);
                });
            }
        });
    },
    /**
     *
     * @param selector  渲染位置  支持选择器
     * @param model  模板 id
     * @param data  数据
     */
    artTemplate: function (selector, model, data) {
        $(selector).html(template(model, data))
    },
    /**
     *  *******自定义表单验证*********
     *  例如：
     *      form.verify({
                  username: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                      return '用户名不能有特殊字符';
                    }
                    if(/(^\_)|(\__)|(\_+$)/.test(value)){
                      return '用户名首尾不能出现下划线\'_\'';
                    }
                    if(/^\d+\d+\d$/.test(value)){
                      return '用户名不能全为数字';
                    }
                  }
                  //我们既支持上述函数式的方式，也支持下述数组的形式
                  //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
                  ,pass: [
                    /^[\S]{6,12}$/
                    ,'密码必须6到12位，且不能出现空格'
                  ]
           });
     *  常规验证：
     *      layui表单元素的校验只需在元素上加入lay-verify
     *           required（必填项）
     phone（手机号）
     email（邮箱）
     url（网址）
     number（数字）
     date（日期）
     identity（身份证）
     *
     *
     */
    formVerify: function (_options) {
        layui.use(['form', 'layer'], function () {
            var form = layui.form;
            form.verify(_options);
        });
    },
    /**
     filterName:  监听提交按钮   例如：filterName： updateSubmit   <button class="layui-btn" lay-submit  lay-filter="updateSubmit" >保存</button>
     url: 提交路径
     formId:form表单ID
     success:放回结果
     * @param _options
     */
    formSubmit: function (_options) {
        layui.use(['form', 'layer'], function () {
            var form = layui.form,
                $ = layui.jquery;
            form.on("submit(" + _options.filterName + ")", function (data) {
                _options.method = 'post';
                _options.async = true;
                _options.data = $("#" + _options.formId).serialize();
                layuiFunciton.ajaxRequest(_options);
            });
        });
    },
    /**
     *
     *  自定义提示框
     *  types:  类型     alert 框   prompt 框   confirm 框   success 成功提示 1   error 错误提示2   warn 警告提示  3 问号 4 锁 7
     *  title: 提示内容
     *
     *  layer.confirm('您确定要删除这条数据吗？', {btn: ['确定','取消'] //按钮}, function(){});
     */
    alert: function (_options) {
        layui.use(['layer'], function () {
            var layer = layui.layer;
            if (_options.types == 'alert') {
                layer.alert(_options.title, _options);
            } else if (_options.types == 'prompt') {
                layer.prompt({});
            } else if (_options.types == 'confirm') {
                layer.confirm(_options.title, {icon: 3, title: '提示信息'}, function (index) {
                    layer.close(index);
                    _options.success();
                });
            } else if (_options.types == 'success') {
                layer.msg(_options.title, {icon: 1, time: 2000}, function () {
                    layuiFunciton.closeOpen();
                });
            } else if (_options.types == 'error') {
                layer.msg(_options.title, {icon: 2, time: 2000}, function () {
                    layuiFunciton.closeOpen();
                });
            } else if (_options.types == 'warn') {
                layer.msg(_options.title, {icon: 7, time: 2000});
            }
        });
    },
    /*警告提示*/
    warn: function (title, success) {
        layer.msg(title, {icon: 7, time: 2000}, success);
    },
    /*警告提示*/
    warnAlert: function (title, success) {
        layer.alert(title, {icon: 7, title: "提示"}, success);
    },
    /*成功*/
    success: function (title, success) {
        layer.msg(title, {icon: 1, time: 2000}, success);
    },
    /*失败*/
    error: function (title, success) {
        layer.msg(title, {icon: 2, time: 2000}, success);
    },
    /**
     *  监听事件
     *
     types:'form',   //   注：仅支持 from 、table 两种类型  监听 table的 tools
     filterTypes: 'switch',   //
     filterName: 'enabledDemo',
     returnData : function (obj) {
             layer.alert('编辑行：<br>'+ JSON.stringify(obj));
         }
     * @param _options
     */
    filter: function (_options) {
        layui.use(['form', 'table', 'layer'], function () {
            var layer = layui.layer
                , table = layui.table
                , form = layui.form;
            if (_options.types == 'form') {
                form.on(_options.filterTypes + '(' + _options.filterName + ')', _options.returnData);
            } else if (_options.types == 'table') {
                table.on(_options.filterTypes + '(' + _options.filterName + ')', _options.returnData);
            }
        });
    },
    /**
     * 关闭 open 框
     */
    closeOpen: function (obj) {
        if (obj) {
            obj.layerObj.close(obj.index);
        } else {
            var obj = window.parent.opneLayer == undefined ? window.opneLayer : window.parent.opneLayer;
            obj.layerObj.close(obj.index);
        }
    },
    /**
     *  title  名称
     *  url 页面路径
     * @param _options
     */
    //根据页面路径打开页面
    addTab: function (_options) {
        var element = window.element == undefined ? window.parent.element : window.element
            , menu = [], tabIndex = -1;
        $(".layui-tab-title.top_tab li").each(function () {
            if ($(this).find("cite").text() == _options.title) {
                tabIndex = 1;
            }
        });
        if (tabIndex == -1) {
            if (window.sessionStorage.getItem("menu")) {
                menu = JSON.parse(window.sessionStorage.getItem("menu"));
            }
            var id = new Date().getTime();
            element.tabAdd('bodyTab', {
                title: '<cite>' + _options.title + '</cite><i class="layui-icon layui-unselect layui-tab-close" data-id="' + _options.id + '">&#x1006;</i>',
                content: "<iframe src='" + _options.url + "' data-id='" + _options.id + "'></frame>",
                id: id
            });
            //当前窗口内容
            var curmenu = {
                "icon": "",
                "title": _options.title,
                "href": _options.url,
                "layId": new Date().getTime()
            };
            menu.push(curmenu);
            window.sessionStorage.setItem("menu", JSON.stringify(menu)); //打开的窗口
            window.sessionStorage.setItem("curmenu", JSON.stringify(curmenu)); //当前的窗口
            element.tabChange("bodyTab", id);
        } else {
            //当前窗口内容
            /*var curmenu = {
             "icon": _this.find("i.seraph").attr("data-icon") != undefined ? _this.find("i.seraph").attr("data-icon") : _this.find("i.layui-icon").attr("data-icon"),
             "title": _this.find("cite").text(),
             "href": _this.attr("data-url")
             };
             that.changeRegresh(_this.parent('.layui-nav-item').index());
             window.sessionStorage.setItem("curmenu", JSON.stringify(curmenu)); //当前的窗口
             element.tabChange(tabFilter, that.getLayId(_this.find("cite").text()));*/
        }

    },
    /**
     * 时间控件
     elem: '',
     format: 'yyyy-MM-dd',
     trigger: 'click',
     max : 0,
     done: function(value, date){
         }
     * @param _options
     */
    layTime: function (_options) {
        //$(_options.elem).before('<i class="layui-icon i">&#xe637;</i>');
        _options = $.extend({
            elem: '',
            format: 'yyyy-MM-dd',
            trigger: 'click',
            done: function (value, date) {
            }
        }, _options);
        layui.use(['laydate'], function () {
            var laydate = layui.laydate;
            laydate.render(_options);
        });
    },
    /**
     elem: '.userFaceBtn',   //触发选择器
     url: '../json/userface.json',   //上传路劲
     accept: 'file', //普通文件
     done: function(res, index, upload){    //返回函数
            var num = parseInt(4*Math.random());  //生成0-4的随机数，随机显示一个头像信息
            $('#userFace').attr('src',res.data[num].src);
            window.sessionStorage.setItem('userFace',res.data[num].src);
        }
     */
    uploadFile: function (_options) {
        _options = $.extend({
            elem: '.userFaceBtn',
            url: '',
            method: "post",  //此处是为了演示之用，实际使用中请将此删除，默认用post方式提交
            done: function (res, index, upload) {
            }
        }, _options);
        layui.use(['upload'], function () {
            var upload = layui.upload;
            upload.render(_options);
        });
    }
});

$(function () {

    //权限
    //当前菜单ID
    var currentMenuId = window.currentMenuId == undefined ? window.parent.currentMenuId : window.currentMenuId;
    //获取菜单权限
    var metadataList = window.metadata == undefined ? window.parent.metadata : window.metadata;
    //遍历按钮
    if (currentMenuId != undefined && metadataList[currentMenuId] != undefined) {
        var list = metadataList[currentMenuId];
        var metadata = {};
        $.each(eval(list), function (index, value, array) {
            if (value.metadataTypes == 3) {
                if (metadata[value.metadataPath] == undefined) {
                    metadata[value.metadataPath] = '<a class="layui-btn layui-btn-sm addeg_btn" lay-event="' + value.metadataCode + '">' + value.metadataName + '</a>'
                } else {
                    metadata[value.metadataPath] += '<a class="layui-btn layui-btn-sm addeg_btn" lay-event="' + value.metadataCode + '">' + value.metadataName + '</a>';
                }
            }
        });
        Object.keys(metadata).forEach(function (key) {
            $(key).html('<div class="layui-btn-container">' + metadata[key] + '</div>');
        });
    }
    /*else{
     if(currentMenuId>0){
     layuiFunciton.ajaxRequest({
     url:  layuiFunciton.URL + '/sysMetadata/findSysMetadataPage',
     method: 'get',
     data: {
     page: 1,
     limit: 15,
     menuId: currentMenuId
     },
     success: function(data){
     console.log(data)
     }
     });
     pageReady();
     }
     }*/
// 控制更多查询条件的显示和隐藏
    $(".layui-searchM").hide();
    $(".layui-search-more").click(function (event) {
        if ($(".layui-searchM").css('display') == "none") {
            $(".layui-search-more .layui-icon").html("&#xe619;");
        } else {
            $(".layui-search-more .layui-icon").html("&#xe61a;");
        }
        $(".layui-searchM").slideToggle();
    });

    //树动态高度
    var treeHeight = $(window).height() - 80;
    $(".ztree").css("height", treeHeight);
    $(window).resize(function () {
        treeHeight = $(window).height() - 80;
        $(".ztree").css("height", treeHeight);
    });
});

/*!
 *
 * JavaScript 模板引擎
 * - artTemplate
 *
 */

!(function () {
    String.prototype.replaceAll = function (s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
    };
    /**
     * 模板引擎
     * @name    template
     * @param   {String}            模板名
     * @param   {Object, String}    数据。如果为字符串则编译并缓存编译结果
     * @return  {String, Function}  渲染好的HTML字符串或者渲染方法
     */
    var template = function (filename, content) {
        return typeof content === 'string'
            ? compile(content, {
                filename: filename
            })
            : renderFile(filename, content);
    };


    template.version = '3.0.0';


    /**
     * 设置全局配置
     * @name    template.config
     * @param   {String}    名称
     * @param   {Any}       值
     */
    template.config = function (name, value) {
        defaults[name] = value;
    };


    var defaults = template.defaults = {
        openTag: '<%',    // 逻辑语法开始标签
        closeTag: '%>',   // 逻辑语法结束标签
        escape: true,     // 是否编码输出变量的 HTML 字符
        cache: true,      // 是否开启缓存（依赖 options 的 filename 字段）
        compress: false,  // 是否压缩输出
        parser: null      // 自定义语法格式器 @see: template-syntax.js
    };


    var cacheStore = template.cache = {};


    /**
     * 渲染模板
     * @name    template.render
     * @param   {String}    模板
     * @param   {Object}    数据
     * @return  {String}    渲染好的字符串
     */
    template.render = function (source, options) {
        return compile(source, options);
    };


    /**
     * 渲染模板(根据模板名)
     * @name    template.render
     * @param   {String}    模板名
     * @param   {Object}    数据
     * @return  {String}    渲染好的字符串
     */
    var renderFile = template.renderFile = function (filename, data) {
        var fn = template.get(filename) || showDebugInfo({
                filename: filename,
                name: 'Render Error',
                message: 'Template not found'
            });
        return data ? fn(data) : fn;
    };


    /**
     * 获取编译缓存（可由外部重写此方法）
     * @param   {String}    模板名
     * @param   {Function}  编译好的函数
     */
    template.get = function (filename) {

        var cache;

        if (cacheStore[filename]) {
            // 使用内存缓存
            cache = cacheStore[filename];
        } else if (typeof document === 'object') {
            // 加载模板并编译
            var elem = document.getElementById(filename);

            if (elem) {
                var source = (elem.value || elem.innerHTML)
                    .replace(/^\s*|\s*$/g, '');
                cache = compile(source, {
                    filename: filename
                });
            } else {
                filename = filename.replaceAll('="=', '==');
                filename = filename.replaceAll('=="', '==');
                filename = filename.replaceAll('=""', ' ');
                filename = filename.replaceAll('  if', '/if');
                filename = filename.replaceAll('else/if', 'else if');
                filename = filename.replaceAll('/&gt;', '/>');
                var source = filename.replace(/^\s*|\s*$/g, '');
                cache = compile(source, {
                    filename: filename
                });
            }
        }

        return cache;
    };


    var toString = function (value, type) {

        if (typeof value !== 'string') {

            type = typeof value;
            if (type === 'number') {
                value += '';
            } else if (type === 'function') {
                value = toString(value.call(value));
            } else {
                value = '';
            }
        }

        return value;

    };


    var escapeMap = {
        "<": "&#60;",
        ">": "&#62;",
        '"': "&#34;",
        "'": "&#39;",
        "&": "&#38;"
    };


    var escapeFn = function (s) {
        return escapeMap[s];
    };

    var escapeHTML = function (content) {
        return toString(content)
            .replace(/&(?![\w#]+;)|[<>"']/g, escapeFn);
    };


    var isArray = Array.isArray || function (obj) {
            return ({}).toString.call(obj) === '[object Array]';
        };


    var each = function (data, callback) {
        var i, len;
        if (isArray(data)) {
            for (i = 0, len = data.length; i < len; i++) {
                callback.call(data, data[i], i, data);
            }
        } else {
            for (i in data) {
                callback.call(data, data[i], i);
            }
        }
    };


    var utils = template.utils = {

        $helpers: {},

        $include: renderFile,

        $string: toString,

        $escape: escapeHTML,

        $each: each

    };
    /**
     * 添加模板辅助方法
     * @name    template.helper
     * @param   {String}    名称
     * @param   {Function}  方法
     */
    template.helper = function (name, helper) {
        helpers[name] = helper;
    };

    var helpers = template.helpers = utils.$helpers;


    /**
     * 模板错误事件（可由外部重写此方法）
     * @name    template.onerror
     * @event
     */
    template.onerror = function (e) {
        var message = 'Template Error\n\n';
        for (var name in e) {
            message += '<' + name + '>\n' + e[name] + '\n\n';
        }

        if (typeof console === 'object') {
            console.error(message);
        }
    };


// 模板调试器
    var showDebugInfo = function (e) {

        template.onerror(e);

        return function () {
            return '{Template Error}';
        };
    };


    /**
     * 编译模板
     * 2012-6-6 @TooBug: define 方法名改为 compile，与 Node Express 保持一致
     * @name    template.compile
     * @param   {String}    模板字符串
     * @param   {Object}    编译选项
     *
     *      - openTag       {String}
     *      - closeTag      {String}
     *      - filename      {String}
     *      - escape        {Boolean}
     *      - compress      {Boolean}
     *      - debug         {Boolean}
     *      - cache         {Boolean}
     *      - parser        {Function}
     *
     * @return  {Function}  渲染方法
     */
    var compile = template.compile = function (source, options) {

        // 合并默认配置
        options = options || {};
        for (var name in defaults) {
            if (options[name] === undefined) {
                options[name] = defaults[name];
            }
        }


        var filename = options.filename;


        try {

            var Render = compiler(source, options);

        } catch (e) {

            e.filename = filename || 'anonymous';
            e.name = 'Syntax Error';

            return showDebugInfo(e);

        }


        // 对编译结果进行一次包装

        function render(data) {

            try {

                return new Render(data, filename) + '';

            } catch (e) {

                // 运行时出错后自动开启调试模式重新编译
                if (!options.debug) {
                    options.debug = true;
                    return compile(source, options)(data);
                }

                return showDebugInfo(e)();

            }

        }


        render.prototype = Render.prototype;
        render.toString = function () {
            return Render.toString();
        };


        if (filename && options.cache) {
            cacheStore[filename] = render;
        }


        return render;

    };


// 数组迭代
    var forEach = utils.$each;


// 静态分析模板变量
    var KEYWORDS =
        // 关键字
        'break,case,catch,continue,debugger,default,delete,do,else,false'
        + ',finally,for,function,if,in,instanceof,new,null,return,switch,this'
        + ',throw,true,try,typeof,var,void,while,with'

        // 保留字
        + ',abstract,boolean,byte,char,class,const,double,enum,export,extends'
        + ',final,float,goto,implements,import,int,interface,long,native'
        + ',package,private,protected,public,short,static,super,synchronized'
        + ',throws,transient,volatile'

        // ECMA 5 - use strict
        + ',arguments,let,yield'

        + ',undefined';

    var REMOVE_RE = /\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|\s*\.\s*[$\w\.]+/g;
    var SPLIT_RE = /[^\w$]+/g;
    var KEYWORDS_RE = new RegExp(["\\b" + KEYWORDS.replace(/,/g, '\\b|\\b') + "\\b"].join('|'), 'g');
    var NUMBER_RE = /^\d[^,]*|,\d[^,]*/g;
    var BOUNDARY_RE = /^,+|,+$/g;
    var SPLIT2_RE = /^$|,+/;


// 获取变量
    function getVariable(code) {
        return code
            .replace(REMOVE_RE, '')
            .replace(SPLIT_RE, ',')
            .replace(KEYWORDS_RE, '')
            .replace(NUMBER_RE, '')
            .replace(BOUNDARY_RE, '')
            .split(SPLIT2_RE);
    };


// 字符串转义
    function stringify(code) {
        return "'" + code
            // 单引号与反斜杠转义
                .replace(/('|\\)/g, '\\$1')
                // 换行符转义(windows + linux)
                .replace(/\r/g, '\\r')
                .replace(/\n/g, '\\n') + "'";
    }


    function compiler(source, options) {

        var debug = options.debug;
        var openTag = options.openTag;
        var closeTag = options.closeTag;
        var parser = options.parser;
        var compress = options.compress;
        var escape = options.escape;


        var line = 1;
        var uniq = {$data: 1, $filename: 1, $utils: 1, $helpers: 1, $out: 1, $line: 1};


        var isNewEngine = ''.trim;// '__proto__' in {}
        var replaces = isNewEngine
            ? ["$out='';", "$out+=", ";", "$out"]
            : ["$out=[];", "$out.push(", ");", "$out.join('')"];

        var concat = isNewEngine
            ? "$out+=text;return $out;"
            : "$out.push(text);";

        var print = "function(){"
            + "var text=''.concat.apply('',arguments);"
            + concat
            + "}";

        var include = "function(filename,data){"
            + "data=data||$data;"
            + "var text=$utils.$include(filename,data,$filename);"
            + concat
            + "}";

        var headerCode = "'use strict';"
            + "var $utils=this,$helpers=$utils.$helpers,"
            + (debug ? "$line=0," : "");

        var mainCode = replaces[0];

        var footerCode = "return new String(" + replaces[3] + ");"

        // html与逻辑语法分离
        forEach(source.split(openTag), function (code) {
            code = code.split(closeTag);

            var $0 = code[0];
            var $1 = code[1];

            // code: [html]
            if (code.length === 1) {

                mainCode += html($0);

                // code: [logic, html]
            } else {

                mainCode += logic($0);

                if ($1) {
                    mainCode += html($1);
                }
            }


        });

        var code = headerCode + mainCode + footerCode;

        // 调试语句
        if (debug) {
            code = "try{" + code + "}catch(e){"
                + "throw {"
                + "filename:$filename,"
                + "name:'Render Error',"
                + "message:e.message,"
                + "line:$line,"
                + "source:" + stringify(source)
                + ".split(/\\n/)[$line-1].replace(/^\\s+/,'')"
                + "};"
                + "}";
        }


        try {


            var Render = new Function("$data", "$filename", code);
            Render.prototype = utils;

            return Render;

        } catch (e) {
            e.temp = "function anonymous($data,$filename) {" + code + "}";
            throw e;
        }


        // 处理 HTML 语句
        function html(code) {

            // 记录行号
            line += code.split(/\n/).length - 1;

            // 压缩多余空白与注释
            if (compress) {
                code = code
                    .replace(/\s+/g, ' ')
                    .replace(/<!--[\w\W]*?-->/g, '');
            }

            if (code) {
                code = replaces[1] + stringify(code) + replaces[2] + "\n";
            }

            return code;
        }


        // 处理逻辑语句
        function logic(code) {

            var thisLine = line;

            if (parser) {

                // 语法转换插件钩子
                code = parser(code, options);

            } else if (debug) {

                // 记录行号
                code = code.replace(/\n/g, function () {
                    line++;
                    return "$line=" + line + ";";
                });

            }


            // 输出语句. 编码: <%=value%> 不编码:<%=#value%>
            // <%=#value%> 等同 v2.0.3 之前的 <%==value%>
            if (code.indexOf('=') === 0) {

                var escapeSyntax = escape && !/^=[=#]/.test(code);

                code = code.replace(/^=[=#]?|[\s;]*$/g, '');

                // 对内容编码
                if (escapeSyntax) {

                    var name = code.replace(/\s*\([^\)]+\)/, '');

                    // 排除 utils.* | include | print

                    if (!utils[name] && !/^(include|print)$/.test(name)) {
                        code = "$escape(" + code + ")";
                    }

                    // 不编码
                } else {
                    code = "$string(" + code + ")";
                }


                code = replaces[1] + code + replaces[2];

            }

            if (debug) {
                code = "$line=" + thisLine + ";" + code;
            }

            // 提取模板中的变量名
            forEach(getVariable(code), function (name) {

                // name 值可能为空，在安卓低版本浏览器下
                if (!name || uniq[name]) {
                    return;
                }

                var value;

                // 声明模板变量
                // 赋值优先级:
                // [include, print] > utils > helpers > data
                if (name === 'print') {

                    value = print;

                } else if (name === 'include') {

                    value = include;

                } else if (utils[name]) {

                    value = "$utils." + name;

                } else if (helpers[name]) {

                    value = "$helpers." + name;

                } else {

                    value = "$data." + name;
                }

                headerCode += name + "=" + value + ",";
                uniq[name] = true;


            });

            return code + "\n";
        }


    };


// 定义模板引擎的语法


    defaults.openTag = '{{';
    defaults.closeTag = '}}';


    var filtered = function (js, filter) {
        var parts = filter.split(':');
        var name = parts.shift();
        var args = parts.join(':') || '';

        if (args) {
            args = ', ' + args;
        }

        return '$helpers.' + name + '(' + js + args + ')';
    }


    defaults.parser = function (code, options) {

        // var match = code.match(/([\w\$]*)(\b.*)/);
        // var key = match[1];
        // var args = match[2];
        // var split = args.split(' ');
        // split.shift();

        code = code.replace(/^\s/, '');

        var split = code.split(' ');
        var key = split.shift();
        var args = split.join(' ');


        switch (key) {

            case 'if':

                code = 'if(' + args + '){';
                break;

            case 'else':

                if (split.shift() === 'if') {
                    split = ' if(' + split.join(' ') + ')';
                } else {
                    split = '';
                }

                code = '}else' + split + '{';
                break;

            case '/if':

                code = '}';
                break;

            case 'each':

                var object = split[0] || '$data';
                var as = split[1] || 'as';
                var value = split[2] || '$value';
                var index = split[3] || '$index';

                var param = value + ',' + index;

                if (as !== 'as') {
                    object = '[]';
                }

                code = '$each(' + object + ',function(' + param + '){';
                break;

            case '/each':

                code = '});';
                break;

            case 'echo':

                code = 'print(' + args + ');';
                break;

            case 'print':
            case 'include':

                code = key + '(' + split.join(',') + ');';
                break;

            default:

                // 过滤器（辅助方法）
                // {{value | filterA:'abcd' | filterB}}
                // >>> $helpers.filterB($helpers.filterA(value, 'abcd'))
                // TODO: {{ddd||aaa}} 不包含空格
                if (/^\s*\|\s*[\w\$]/.test(args)) {

                    var escape = true;

                    // {{#value | link}}
                    if (code.indexOf('#') === 0) {
                        code = code.substr(1);
                        escape = false;
                    }

                    var i = 0;
                    var array = code.split('|');
                    var len = array.length;
                    var val = array[i++];

                    for (; i < len; i++) {
                        val = filtered(val, array[i]);
                    }

                    code = (escape ? '=' : '=#') + val;

                    // 即将弃用 {{helperName value}}
                } else if (template.helpers[key]) {

                    code = '=#' + key + '(' + split.join(',') + ');';

                    // 内容直接输出 {{value}}
                } else {

                    code = '=' + code;
                }

                break;
        }


        return code;
    };


// RequireJS && SeaJS
    if (typeof define === 'function') {
        define(function () {
            return template;
        });

// NodeJS
    } else if (typeof exports !== 'undefined') {
        module.exports = template;
    } else {
        this.template = template;
    }

})();

/**
 * 根据valCode获取名称
 * @param valCode
 */
function getDicVal(valCode) {
    var valName = '';
    layuiFunciton.ajaxRequest({
        url: layuiFunciton.URL + '/sys/dictVal/getValNameByValCode',
        method: 'get',
        data: {valCode: valCode},
        success: function (data) {
            valName = data.valName;
        }
    })
    return valName;
}

/**
 *
 * @param typeCode
 * @returns {string}
 */
function getDicValByType(typeCode) {
    var dicList = [];
    layuiFunciton.ajaxRequest({
        url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode',
        method: 'get',
        data: {typeCode: typeCode},
        success: function (data) {
            dicList = data;
        }
    })
    return dicList;
}


function getUrlParam(name) {
    // 用该属性获取页面 URL 地址从问号 (?) 开始的 URL（查询部分）
    var url = window.location.search;
    // 正则筛选地址栏
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    // 匹配目标参数
    var result = url.substr(1).match(reg);
    //返回参数值
    return result ? decodeURIComponent(result[2]) : null;
}